﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Numerics;
using System.Reflection;
using System.Threading;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.DataAccess.Common;
using T.FAS.Runtime.Expression.Entity;
using T.FAS.Runtime.Expression.Plugin;
using T.FAS.Runtime.Expression.Service;
using T.ServiceComponent.Common.Service;

namespace T.FAS.Runtime.Expression.UnitTest
{
    [TestClass]
    public class FuncUnit
    {
        #region Math
        /// <summary>
        /// Abs 绝对值
        /// </summary>
        [TestMethod]
        public void Abs()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Abs(-2)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 2);
        }
        /// <summary>
        /// Mod 取余
        /// </summary>
        [TestMethod]
        public void Mod()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Mod(5,4)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 1);
        }
        /// <summary>
        /// Power 平方
        /// </summary>
        [TestMethod]
        public void Power()
        {
            int id = System.Threading.Thread.CurrentThread.ManagedThreadId;
            Dictionary<string, object> dic = new Dictionary<string, object>();

            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetThreadID()", dic);
            Assert.IsTrue(exprResult.Result.ToString() == id.ToString());
        }
        /// <summary>
        /// Round 四舍五入
        /// </summary>
        [TestMethod]
        public void Round()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Round(5.6)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 6);
        }
        /// <summary>
        /// Sqrt 根号
        /// </summary>
        [TestMethod]
        public void Sqrt()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Sqrt(4)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 2);
        }
        /// <summary>
        /// Trunc 向下取整
        /// </summary>
        [TestMethod]
        public void Trunc()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Trunc(8.5)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 8);
        }
        #endregion
        #region Numeric
        /// <summary>
        /// Max
        /// </summary>
        [TestMethod]
        public void Max()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Max(3,54)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 54);
        }
        [TestMethod]
        public void ToFix()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.DiffHours('2022-01-01 12:23:59','2022-01-02 12:12:59').toFixed(1)", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "23.8");
        }
        /// <summary>
        /// Min
        /// </summary>
        [TestMethod]
        public void Min()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Min(3,54)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 3);
        }
        /// <summary>
        /// Sign 正数1 负数-1 00 
        /// </summary>
        [TestMethod]
        public void Sign()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Sign(-54)", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == -1);
        }
        #endregion
        #region String
        /// <summary>
        /// Chr 连接字符串
        /// </summary>
        [TestMethod]
        public void Chr()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Chr(88)", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "X");
        }
        /// <summary>
        /// Concat 连接字符串
        /// </summary>
        [TestMethod]
        public void Concat()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Concat('dsds','fd')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "dsdsfd");
        }
        /// <summary>
        /// EncodeHtml 替换字符串中的特殊字符
        /// </summary>
        [TestMethod]
        public void EncodeHtml()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.EncodeHtml('<>')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "&lt;&gt;");

            exprResult = ExprService.GetInstance.JSExecute("Funcs.EncodeHtml(\"another ' test\")", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "another &#39; test");
        }
        /// <summary>
        /// EncodeUrl 替换字符串中的特殊字符
        /// </summary>
        [TestMethod]
        public void EncodeUrl()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.EncodeUrl(' test')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "+test");

            exprResult = ExprService.GetInstance.JSExecute("Funcs.EncodeUrl(\"another ' test\")", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "another+%27+test");
        }
        /// <summary>
        /// Guid
        /// </summary>
        [TestMethod]
        public void Guid()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Guid()", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// Length
        /// </summary>
        [TestMethod]
        public void Length()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Length('First string')", dic);
            Assert.IsTrue(Convert.ToInt32(exprResult.Result.ToString()) == 12);
        }
        /// <summary>
        /// Replace 替换
        /// </summary>
        [TestMethod]
        public void Replace()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Replace('First string', 'xx', '')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "First string");
        }
        /// <summary>
        /// Substr 截取
        /// </summary>
        [TestMethod]
        public void Substr()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Substr('First string', 2, 4)", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "rst ");
        }
        /// <summary>
        /// ToLower 转小写
        /// </summary>
        [TestMethod]
        public void ToLower()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.ToLower('First string')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "first string");
        }
        /// <summary>
        /// ToUpper 转大写
        /// </summary>
        [TestMethod]
        public void ToUpper()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.ToUpper('First string')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "FIRST STRING");
        }
        /// <summary>
        /// Trim 去空格
        /// </summary>
        [TestMethod]
        public void Trim()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Trim(' First string ')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "First string");
        }
        /// <summary>
        /// TrimEnd 去空格
        /// </summary>
        [TestMethod]
        public void TrimEnd()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.TrimEnd(' First string ')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == " First string");
        }
        /// <summary>
        /// TrimStart 去空格
        /// </summary>
        [TestMethod]
        public void TrimStart()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.TrimStart(' First string ')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "First string ");
        }
        #endregion
        #region Date and Time
        /// <summary>
        /// AddDays
        /// </summary>
        [TestMethod]
        public void AddDays()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.AddDays(Funcs.CurrDate(),4)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// AddDays
        /// </summary>
        [TestMethod]
        public void AddDaysErr()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("AA.AddDays()", dic);
            Assert.IsTrue(exprResult.ErrMsg == "AA is not defined");
            exprResult = ExprService.GetInstance.JSExecute("Funcs.AddDays('2000',2)", dic);
            Assert.IsTrue(exprResult.ErrMsg == "Unrecognized date/time format 2000");
        }
        /// <summary>
        /// AddHours
        /// </summary>
        [TestMethod]
        public void AddHours()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.AddHours(Funcs.CurrDateTime(),4)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// AddHours
        /// </summary>
        [TestMethod]
        public void GroupTest()
        {
            Group group = new Group();
            group.AddFilter(new Filter { Code = "Student.Name", Condition = "contains", Value = new List<string> { "张" } });
            group.AddFilter(new FRelation { Relation = "and" },
                new Filter { Code = "Student.Age", Condition = ">", Value = new List<string> { "10" } });
            var dic = new Dictionary<string, object>();
            dic.Add("Student", new { Sex = "男", Name = "张三", Age = 12 });
            var exprGroupString = JsonConvert.SerializeObject(group);
            ExprResult result = ExprService.GetInstance.GroupExecute(exprGroupString, dic);

            Assert.IsTrue(Convert.ToBoolean(result.Result));

            dic.Add("Class", new { Name = "六年级三班", Teacher = "王老师" });
            group.AddFilter(new FRelation { Relation = "and" },
                new Filter { Code = "Class.Name", Condition = "=", Value = new List<string> { "六年级四班" } });
            exprGroupString = JsonConvert.SerializeObject(group);
            result = ExprService.GetInstance.GroupExecute(exprGroupString, dic);

            Assert.IsFalse(Convert.ToBoolean(result.Result));
        }
        /// <summary>
        /// GetWeekNum
        /// </summary>
        [TestMethod]
        public void GetWeekNum()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetWeekNum('2022-11-12')", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetFisrtDayOfTheWeekByWeekNo
        /// </summary>
        [TestMethod]
        public void GetFisrtDayOfTheWeekByWeekNo()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetFisrtDayOfTheWeekByWeekNo(2022,45)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetFisrtDayOfTheWeekByWeekNo
        /// </summary>
        [TestMethod]
        public void GetLastDayOfTheWeekByWeekNo()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetLastDayOfTheWeekByWeekNo(2022,45)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// CurrDate
        /// </summary>
        [TestMethod]
        public void CurrDate()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.CurrDate()", dic);
            Assert.IsTrue(exprResult.Result.ToString() == DateTime.Now.ToString("yyyy-MM-dd"));
        }
        /// <summary>
        /// Day
        /// </summary>
        [TestMethod]
        public void Day()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.Day('2022-01-25 12:23:59')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "25");
        }
        /// <summary>
        /// DayOfWeek
        /// </summary>
        [TestMethod]
        public void DayOfWeek()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.DayOfWeek('2022-01-25 12:23:59')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "2");
        }
        /// <summary>
        /// DayOfWeek
        /// </summary>
        [TestMethod]
        public void DiffDays()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.DiffDays('2022-01-01 12:23:59','2022-01-25 12:23:59')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "24");
        }
        /// <summary>
        /// GetDateDiff
        /// </summary>
        [TestMethod]
        public void GetDateDiff()
        {
            T.ServiceComponent.I18N.Service.LiveDebugService.StartLiveDebug(); 
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetDateDiff(Funcs.AddDays(Funcs.CurrDate(),-80))", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
            T.ServiceComponent.I18N.Service.LiveDebugService.StopLiveDebug();
        }
        /// <summary>
        /// GetFirstDayOfTheYear
        /// </summary>
        [TestMethod]
        public void GetFirstDayOfTheYear()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetFirstDayOfTheYear(Funcs.CurrDate())", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetLastDayOfTheYear
        /// </summary>
        [TestMethod]
        public void GetLastDayOfTheYear()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetLastDayOfTheYear(Funcs.CurrDate())", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetFisrtDayOfTheQuarter
        /// </summary>
        [TestMethod]
        public void GetFisrtDayOfTheQuarter()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetFisrtDayOfTheQuarter(Funcs.CurrDate())", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetLastDayOfTheQuarter
        /// </summary>
        [TestMethod]
        public void GetLastDayOfTheQuarter()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetLastDayOfTheQuarter(Funcs.CurrDate())", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetFisrtDayOfTheWeek
        /// </summary>
        [TestMethod]
        public void GetFisrtDayOfTheWeek()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetFisrtDayOfTheWeek(Funcs.CurrDate())", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GetLastDayOfTheWeek
        /// </summary>
        [TestMethod]
        public void GetLastDayOfTheWeek()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetLastDayOfTheWeek(Funcs.CurrDate())", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        #endregion
        #region Data Conversion
        /// <summary>
        /// TimeToString
        /// </summary>
        [TestMethod]
        public void TimeToString()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.TimeToString('12:32:43')", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void StringToDate2()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.StringToDate('2023-12-07 12:12:12')", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void StringToDateTime1()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.StringToDateTime('Fri Oct 06 2023 01:45:12 GMT+0800')", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void StringToDateTime()
        {
            DateTime dt = DateTime.Now;
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.StringToDateTime(null)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void DateTimeToString()
        {
            var cultureInfo = new CultureInfo("pt-BR");
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.DateTimeToString('2023/12/07 12:12:12')", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        #endregion
        #region Format
        /// <summary>
        /// FormatCurrency
        /// </summary>
        [TestMethod]
        public void FormatCurrency()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.FormatCurrency(432421323.43,2,'$',',','.')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "$432,421,323.43");
        }
        /// <summary>
        /// FormatDateTime
        /// </summary>
        [TestMethod]
        public void FormatDateTime()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.FormatDateTime('2022-01-01 12:23:59','yyyy-MM')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "2022-01");
        }
        #endregion
        #region Miscellaneous
        /// <summary>
        /// If
        /// </summary>
        [TestMethod]
        public void EmailAddressValidate()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.EmailAddressValidate('3962@qq.com')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "True");

            exprResult = ExprService.GetInstance.JSExecute("Funcs.EmailAddressValidate('396d@2@qq.com')", dic);
            Assert.IsTrue(exprResult.Result.ToString() == "False");
        }
        /// <summary>
        /// GeneratePassword
        /// </summary>
        [TestMethod]
        public void GeneratePassword()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GeneratePassword(9,true)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// GeneratePassword
        /// </summary>
        [TestMethod]
        public void TryBoolean2()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("DefaultCDO","");
            ExprResult exprResult = ExprService.GetInstance.JSExecute("(Funcs.TryBoolean(String(DefaultCDO.IsDelete)) == Funcs.TryBoolean(String(1)))", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == false);
        }
        /// <summary>
        /// GeneratePassword
        /// </summary>
        [TestMethod]
        public void TryBoolean()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean(true)", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == true);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean(false)", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == false);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean(1)", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == true);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean(0)", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == false);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean('1')", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == true);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean('0')", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == false);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean('true')", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == true);
            exprResult = ExprService.GetInstance.JSExecute("Funcs.TryBoolean('false')", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result) == false);
        }
        /// <summary>
        /// IsNullOrEmpty
        /// </summary>
        [TestMethod]
        public void IsNullOrEmpty()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.IsNullOrEmpty('')", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result));
        }
        /// <summary>
        /// IsNull
        /// </summary>
        [TestMethod]
        public void IsNull()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.IsNull('')", dic);
            Assert.IsFalse(Convert.ToBoolean(exprResult.Result));
        }
        /// <summary>
        /// IsNullOrEmpty
        /// </summary>
        [TestMethod]
        public void IsNull2()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute(@"var filters = [
            {
                'Code': 'DO_DEP_ProjectBug.Name',
                'Condition': 'notcontains',
                'Value': '【测试】'
            },{
                'Code': 'DO_DEP_ProjectBug.Name',
                'Condition': 'contains',
                'Value': '【测试】'
            }
            ];return Funcs.BuildDQAdvFilter(filters);", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// BuildDQAdvFilter
        /// </summary>
        [TestMethod]
        public void BuildDQAdvFilter()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("var s; Funcs.IsNull(s)", dic);
            Assert.IsTrue(Convert.ToBoolean(exprResult.Result));
        }
        /// <summary>
        /// SendMsgToUser
        /// </summary>
        [TestMethod]
        public void SendMsgToUser()
        {
            //MockService.RegisterHSFHook("T.Core.Notify.SPI.INotifyService", "SendNewUserMessageAsync","");
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.SendMsgToUser('1B71BB5E-34D2-4872-A56C-7B06BE852A94', '标题', '内容')", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
            //MockService.UnRegisterSGHook("T.Core.Notify.SPI.INotifyService");
        }
        /// <summary>
        /// SendMsgToGroup
        /// </summary>
        [TestMethod]
        public void SendMsgToGroup()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("var mobile = [];mobile.push('17606414688'); Funcs.SendMsgToGroup('标题', '内容',mobile,'0f8d8652dfa1928a6fdbe05dfebd56bf4c218a69ee9049caf9cf72beb3c1e8ad','SEC1946e5e5f72a14352440eebac1d860393e114125f603c348332db51a903c3882',false)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// SendMsgToGroup
        /// </summary>
        [TestMethod]
        public void SendMsgToGroup2()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("var mobile = [];mobile.push('17606414688');Funcs.SendMsgToGroup('标题', '内容@17606414688',mobile,'0f8d8652dfa1928a6fdbe05dfebd56bf4c218a69ee9049caf9cf72beb3c1e8ad','SEC1946e5e5f72a14352440eebac1d860393e114125f603c348332db51a903c3882',false)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void NewJToken()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("return Funcs.NewJToken(\"\")", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void Desensitize()
        {
            Maskservice.StartLiveDebug();
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute(@"var setlist =[];
            setlist.push({ ColumnName : 'Mobile', DesensitizationType : 'PhoneNumber' });
            setlist.push({ ColumnName : 'Email', DesensitizationType : 'Email' });

            var persions = [];
            persions.push({ Name : '李四', Mobile : '13811111111', Email : 'lisi@t.com' });
            persions.push({ Name : '朱小明', Mobile : '13822222222', Email : 'zhuxiaoming@t.com' });
            Funcs.Desensitize(persions, setlist); ", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// Funcs
        /// </summary>
        [TestMethod]
        public void GetTerms()
        {
            T.ServiceComponent.I18N.Service.LiveDebugService.StartLiveDebug();
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult2 = ExprService.GetInstance.JSExecute("Funcs.GetTerms('Schema.Common.All','全部')", dic);
            Assert.AreEqual("全部", exprResult2.Result.ToString());
            T.ServiceComponent.I18N.Service.LiveDebugService.StopLiveDebug();
        }
        /// <summary>
        /// @我
        /// </summary>
        [TestMethod]
        public void GetNodeText()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Funcs.GetNodeError()", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);
        }
        /// <summary>
        /// @我
        /// </summary>
        [TestMethod]
        public void TransformGroup()
        {
            Group group = JsonConvert.DeserializeObject<Group>("{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"DO_EMB_TwoStaEnergyConsumptionBills.CreateTime\",\"Condition\":\"between\",\"Value\":[\"@本周一\",\"@本周日\"],\"Name\":\"创建时间\",\"DataType\":\"DateTime\",\"ValueName\":\"@本周\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"CustId.Name\",\"Condition\":\"=\",\"Value\":\"@我\",\"Name\":\"客户名称\",\"DataType\":\"String\",\"ValueName\":\"@我\",\"ValueType\":0}]}");
            ExprService.GetInstance.TransformGroup(group);
            Assert.IsNotNull(group);
        }
        /// <summary>
        /// @7天
        /// </summary>
        [TestMethod]
        public void TransformGroup2()
        {
            Group group = JsonConvert.DeserializeObject<Group>("{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"DO_DEP_Product.ProductName\",\"Condition\":\"contains\",\"Value\":\"研发效能平台\",\"Name\":\"产品\",\"DataType\":\"String\",\"ValueName\":\"研发效能平台\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已终止\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已终止\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已终止\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已终止\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已移除\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已移除\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已完成\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已完成\",\"ValueType\":0}]},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"=\",\"Value\":\"已响应\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已响应\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"DO_DEP_SysRequirement.AnalysisPlanFinishDate\",\"Condition\":\"<>\",\"Value\":null,\"Name\":\"需求分析计划完成日期\",\"DataType\":\"DateTime\",\"ValueName\":null,\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"DO_DEP_SysRequirement.AnalysisPlanFinishDate\",\"Condition\":\"<=\",\"Value\":\"@今天+7\",\"Name\":\"需求分析计划完成日期\",\"DataType\":\"DateTime\",\"ValueName\":\"@今天+7\",\"ValueType\":0}]}]}");
            ExprService.GetInstance.TransformGroup(group);
            Assert.IsNotNull(group);
        }
        /// <summary>
        /// @7天
        /// </summary>
        [TestMethod]
        public void TransformGroup3()
        {
            Group group = JsonConvert.DeserializeObject<Group>("{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"T_Product.Name\",\"Condition\":\"contains\",\"Value\":\"研发效能平台\",\"Name\":\"产品\",\"DataType\":\"String\",\"ValueName\":\"研发效能平台\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已终止\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已终止\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已终止\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已终止\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已移除\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已移除\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"<>\",\"Value\":\"已完成\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已完成\",\"ValueType\":0}]},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"SDO_DEP_SysRequirementState.Name\",\"Condition\":\"=\",\"Value\":\"已响应\",\"Name\":\"状态\",\"DataType\":\"String\",\"ValueName\":\"已响应\",\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Group\",\"Filters\":[{\"ElementType\":\"Filter\",\"Code\":\"DO_DEP_SysRequirement.AnalysisPlanFinishDate\",\"Condition\":\"<>\",\"Value\":null,\"Name\":\"需求分析计划完成日期\",\"DataType\":\"DateTime\",\"ValueName\":null,\"ValueType\":0},{\"ElementType\":\"Relation\",\"Relation\":\"and\"},{\"ElementType\":\"Filter\",\"Code\":\"DO_DEP_SysRequirement.AnalysisPlanFinishDate\",\"Condition\":\"<=\",\"Value\":\"@今天+7\",\"Name\":\"需求分析计划完成日期\",\"DataType\":\"DateTime\",\"ValueName\":\"@今天+7\",\"ValueType\":0}]}]}");
            ExprService.GetInstance.TransformGroup(group);
            Assert.IsNotNull(group);
        }
        /// <summary>
        /// @7天
        /// </summary>
        [TestMethod]
        public void FormatDecimal()
        {
            decimal d = 132423432.23M;
            var s =new FuncsExecutor().FormatDecimal(d, 3, ".", ",");
            Assert.IsNotNull(s);
        }
        #endregion

    }

}
